package com.ly.blog2Common.core.http;

import com.alibaba.fastjson.JSONObject;

/**
 * @Description: 统一返回格式
 * @Authur: lyMaster
 * @Date: 2018/12/30 09:14
 */
public class ResponseMessage {

    private static JSONObject commonResponse(Integer errCode,Object result){

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",errCode);
        jsonObject.put("msg",ErrConfigInit.getErrMsg(errCode));
        if(result != null) {
            jsonObject.put("data", result);
        }
        return jsonObject;
    }

    public static JSONObject ok(){
        return commonResponse(0,null);
    }
    public static JSONObject ok(Object result){
        return commonResponse(0,result);
    }
    public static JSONObject error(Integer errCode){
        return commonResponse(errCode,null);
    }
    public static JSONObject error(Integer errCode,Object result){
        return commonResponse(errCode,result);
    }

}
